package com.apple.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.io.*;
import java.net.Socket;

@Slf4j
@Service
public class BufferRead {

    @Async
    public void read(Socket socket){
        try {
            InputStream inputStream = socket.getInputStream();

            InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
            BufferedReader reader = new BufferedReader(inputStreamReader);

            String inputLine=null;
            while ((inputLine = reader.readLine()) != null) {
                log.info("socket服务端接收到消息：{}",inputLine);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
